package com.example.threadpool2.config;

import com.example.threadpool2.domain.TUserCopy;
import com.example.threadpool2.service.TUserCopyService;
import com.example.threadpool2.utils.SpringContextUtils;

import java.util.List;

/**
 * 任务类
 */
public class MyTask implements Runnable {
    private String name;
    private int[] ints;
    private List<TUserCopy> userList;
    private TUserCopyService userCopyService;


    public MyTask(String name, List<TUserCopy> userList) {
        this.name = name;
        this.userList = userList;
        this.userCopyService = SpringContextUtils.getBeanByClass(TUserCopyService.class);
    }
    public MyTask(String name, int[] ints) {
        this.name = name;
        this.ints = ints;
    }
    public MyTask(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setInts(int[] ints) {
        this.ints= ints;
    }

    @Override
    public void run() {
        try {
            userCopyService.saveBatch(userList);
        } catch (Exception e) {
            throw new RuntimeException("数据库新增数据异常!,{}", e);
        }
    }
}